#include "testlib.h"
#include <string>
#include <vector>
#include <sstream>

using namespace std;
using i64 = long long;

const int N = 2e5 + 10;

int tr[N];
vector<int> g[N];

void add(int p, int x) {
    while(p > 0) {
        tr[p] += x;
        p -= p & -p;
    }
}

int query(int p) {
    int ret = 0;
    while(p < N) {
        ret += tr[p];
        p += p & -p;
    }
    return ret;
}

void dfs(int u, int f, i64 &ans, const vector<int> &p) {
    int x = query(p[u]);
    ans += x + p[u] - 1 - (query(1) - x);
    add(p[u], 1);
    for(int v : g[u])
        if(v != f)
            dfs(v, u, ans, p);
    add(p[u], -1);
}

i64 calcPairs(const vector<int> &p) {
    i64 ret = 0;
    dfs(1, 0, ret, p);
    return ret;
}

int main(int argc, char *argv[]) {
    registerTestlibCmd(argc, argv);

    int n = inf.readInt();
    for(int i = 1, u, v; i < n; i ++) {
        u = inf.readInt();
        v = inf.readInt();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> oufP(n + 1), ansP(n + 1), vis(n + 1, 0);
    for(int i = 1; i <= n; i ++) {
        oufP[i] = ouf.readInt(1, n);
        if(vis[oufP[i]]) quitf(_wa, "Participant's output is not a valid permutation of {1...%d}", n);
        vis[oufP[i]] = 1;
    }

    vis = vector<int>(n + 1);

    for(int i = 1; i <= n; i ++) {
        ansP[i] = ans.readInt(1, n);
        if(vis[ansP[i]]) quitf(_fail, "Judger's output is not a valid permutation of {1...%d}", n);
        vis[ansP[i]] = 1;
    }

    i64 oufv = calcPairs(oufP), ansv = calcPairs(ansP);

    if(oufv < ansv)
        quitf(_wa, "Judger has a better answer than the partipant's one");
    else if(oufv > ansv)
        quitf(_fail, "Partipant's answer is better than the judger's");
    
    quitf(_ok, "Ok %lld pairs", ansv);
}
